<?php

class FInput extends FComponent {
	
	private $frodo;
	
	public $name;
	public $value="Frodo`s Input";
	public $tagName="input";
	public $onPress=null;
	public $style;
	public $maxlength="10";
	public $class;
		
	public function __construct(Frodo $owner,$prototype)
	{
		$owner->__addComponent($this);
		$this->frodo=$owner;
		if($prototype!=null&&$prototype->attributes!=null)
		{
			$this->name=$prototype->getAttribute("name");
			$this->value=$prototype->getAttribute("value");
			$this->onPress=$prototype->getAttribute("onPress");
			$this->style=$prototype->getAttribute("style");
			if(!$this->maxlength=$prototype->getAttribute("maxlength"))
			{
				$this->maxlength="10";
			}
			$this->class=$prototype->getAttribute("class");
		}
		//$owner->dispatchEvent($this);
	}
	
	public function catchPostedValue($val){
		$this->value=$val;
		//echo ("catching! ".$this->name.">>  ".$this->value);
	}
	
	public function getElementXml(DomDocument $xml,$protorype=null){
		$me=$xml->createElement("input");
		$me->setAttribute("type","text");
		$me->setAttribute("name",$this->name);
		$me->setAttribute("id",$this->name);
		$me->setAttribute("value",$this->value);
		if(!empty($this->style)) $me->setAttribute("style",$this->style);
		if(!empty($this->class)) $me->setAttribute("class",$this->class);
		if(!empty($this->maxlength)) $me->setAttribute("maxlength",$this->maxlength);
		return $me;
	}
	
	public function render()
	{
		printf('<input type="submit" name="%s" id="%s" value="%s"/>',
			$this->name,
			$this->name,
			$this->value
		);
	}
}

?>